package unit3;

public class LotteryArray {
	public static void main(String[] args) {
		final int NMAX=10;
		
//		allocate triangular array
		
		int[][] odds=new int[NMAX+1][];
		
		for(int x=0;x<=NMAX;x++){
			odds[x]=new int[x+1];
		}
		
//		fill triangular array
		for(int x=0;x<odds.length;x++)
			for(int y=0;y<odds[x].length;y++){
				/**
				 * compute binomial coefficient n*(n-1)*(n-2)*...*(n-k+1)/(1*2*3*4*...*n)
				 */
				int lotteryOdds=1;
				for(int j=1;j<=y;j++){
					lotteryOdds=lotteryOdds*(x-j+1)/j;
				}
				odds[x][y]=lotteryOdds;
			}
//		print triangular array
		for(int[] row :odds){
			for(int odd:row)
				System.out.printf("%4d" ,odd);
			System.out.println();
		}
	}
}
